// pages/information/information.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 获取学生信息
    stuList:'',
    level:'',
    childNum:''
  },
  // 学生
  getStuList(){
    var app = getApp();
    var UserInfo = app.globalData.UserInfo
    var username = UserInfo.username
    // console.log(username) // 获取   用户名
    var nowtext = UserInfo.nowtext

    let that = this;
    wx.request({
      url:"https://nottoday.club/index.php/api/Scores/getScoresBySTUnumber",
      method:"POST",
      header: { 'cookie': wx.getStorageSync("sessionid") },
      data:{
        STUnumber:username
      },
      success(res){
        // console.log(res);
        if(res.data.status===1){
          that.setData({
            stuList:res.data.data,
            level:nowtext
          })
        }else{
          that.setData({
            stuList: '',
            level: ''
          })
          wx.showModal({
            title: '提示',
            content: '该学生暂无成绩',
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
                wx.switchTab({
                  url: "../my/my",
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
                wx.switchTab({
                  url: "../my/my",
                })
              }
            }
          })
        }
      }
    })
  },
  // 家长
  getChildList(){
    var app = getApp();
    var UserInfo = app.globalData.UserInfo
    var childNum = UserInfo.childNum
    var nowtext = UserInfo.nowtext
    // console.log(childNum)

    let that = this;
    wx.request({
      url:"https://nottoday.club/index.php/api/Scores/getScoresBySTUnumber",
      method:"POST",
      header: { 'cookie': wx.getStorageSync("sessionid") },
      data:{
        STUnumber:childNum
      },
      success(res){
        // console.log(res);
        if(res.data.status===1){
          that.setData({
            stuList:res.data.data,
            level:nowtext
          })
        } else {
          that.setData({
            stuList: '',
            level: ''
          })
          wx.showModal({
            title: '提示',
            content: '该学生暂无成绩',
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
                wx.switchTab({
                  url: "../my/my",
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
                wx.switchTab({
                  url: "../my/my",
                })
              }
            }
          })
        }
      }
    })
  },
  // 班主任
  getHeadList(){
    var app = getApp();
    var UserInfo = app.globalData.UserInfo
    var curGrade = UserInfo.curGrade
    var curClass = UserInfo.curClass
    var nowtext = UserInfo.nowtext

    let that = this;
    wx.request({
      url:"https://nottoday.club/index.php/api/Student/getStudentByClass",
      method:"POST",
      header: { 'cookie': wx.getStorageSync("sessionid") },
      data:{
        grade:curGrade,
        class:curClass
      },
      success(res){
        // console.log(res);
        if(res.data.status===1){
          that.setData({
            stuList:res.data.data,
            level:nowtext
          })
        } else {
          that.setData({
            stuList: '',
            level: ''
          })
          wx.showModal({
            title: '提示',
            content: '无信息',
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
                wx.switchTab({
                  url: "../my/my",
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
                wx.switchTab({
                  url: "../my/my",
                })
              }
            }
          })
        }
      }
    })
  },
  // 辅导员
  getGradeList(){
    var app = getApp();
    var UserInfo = app.globalData.UserInfo
    var curGrade = UserInfo.curGrade
    var nowtext = UserInfo.nowtext

    let that = this;
    wx.request({
      url:"https://nottoday.club/index.php/api/Student/getStudentByGrade",
      method:"POST",
      header: { 'cookie': wx.getStorageSync("sessionid") },
      data:{
        grade:curGrade
      },
      success(res){
        if(res.data.status === 1){
          that.setData({
            stuList:res.data.data,
            level:nowtext
          })
        } else {
          that.setData({
            stuList: '',
            level: ''
          })
          wx.showModal({
            title: '提示',
            content: '无信息',
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
                wx.switchTab({
                  url: "../my/my",
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
                wx.switchTab({
                  url: "../my/my",
                })
              }
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var app = getApp();
    var UserInfo = app.globalData.UserInfo
    var nowtext = UserInfo.nowtext
    if (nowtext >= 901 && nowtext <= 999) {
      // 获取学生信息
      this.getStuList()
    } else if (nowtext >= 889 && nowtext <= 900) {
      // 获取孩子信息
      this.getChildList()
    } else if (nowtext >= 778 && nowtext <= 888) {
      this.getHeadList()
    } else if (nowtext >= 11 && nowtext <= 777) {
      this.getGradeList()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})